import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
// console.log(store)

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/login'),
    hidden: true,
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  // 主页
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' },
      buttonId: 'home.page.index'
    }]
  },
  // 角色管理
  {
    path: '/base',
    component: Layout,
    redirect: '/base',
    name: '基础数据管理',
    meta: { title: '基础数据管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: '/user',
        name: '用户管理',
        component: () => import('@/views/user/index'),
        meta: { title: '用户管理', icon: 'el-icon-s-custom' },
        buttonId: 'base.user.list'
      },
      {
        path: '/role',
        name: '角色管理',
        component: () => import('@/views/role/index'),
        meta: { title: '角色管理', icon: 'el-icon-s-order' },
        buttonId: 'base.role.list'
      },
      {
        path: '/systemLog',
        name: '数据同步',
        component: () => import('@/views/systemLog/index'),
        meta: { title: '数据同步', icon: 'el-icon-stopwatch' },
        buttonId: 'base.data.list'
      }

    ]
  },
  {
    path: '/baseSet',
    component: Layout,
    redirect: '/baseSet',
    name: '基础配置',
    meta: { title: '基础配置', icon: 'el-icon-suitcase-1' },
    children: [
      {
        path: '/project/node',
        name: '项目节点配置',
        component: () => import('@/views/projectNode/index'),
        meta: { title: '项目节点配置', icon: 'el-icon-suitcase' },
        buttonId: 'baseSet.proNode.list'
      },
      {
        path: '/proRole',
        name: '项目角色配置',
        component: () => import('@/views/proRole/index'),
        meta: { title: '项目角色配置', icon: 'el-icon-user' },
        buttonId: 'baseSet.proRole.list'
      },
      {
        path: '/proData',
        name: '项目资料配置',
        component: () => import('@/views/proData/index'),
        meta: { title: '项目资料配置', icon: 'el-icon-notebook-1' },
        buttonId: 'baseSet.proData.list'
      },
      {
        path: '/holiday',
        name: '节假日设置',
        component: () => import('@/views/holiday/index'),
        meta: { title: '节假日设置', icon: 'el-icon-date' },
        buttonId: 'baseSet.holiday.list'
      },
      {
        path: '/branch',
        name: '分社配置',
        component: () => import('@/views/branch/index'),
        meta: { title: '分社配置', icon: 'el-icon-collection' },
        buttonId: 'baseSet.branch.list'
      },
    ]
  },
  {
    path: '/pro',
    component: Layout,
    name: '项目货仓',
    meta: { title: '项目货仓', icon: 'el-icon-document-copy' },
    children: [
      {
        path: '/pro',
        name: 'pro',
        component: () => import('@/views/project/index'),
        meta: { title: '项目货仓', icon: 'el-icon-coin' },
        buttonId: 'project.store.list',
      },
    ]
  },
  {
    path: '/project',
    component: Layout,
    name: '项目管理',
    meta: { title: '项目管理', icon: 'el-icon-document-copy' },
    children: [
      {
        path: '/createProject',
        name: 'createProject',
        component: () => import('@/views/project/createProject/index'),
        meta: { title: '新建项目', icon: 'el-icon-coin' },
        // buttonId: 'project.add.page',
        alwaysShow: false
      },
      {
        path: '/createProject/:id',
        name: 'createProject',
        component: () => import('@/views/project/createProject/index'),
        meta: { title: '编辑项目', icon: 'el-icon-coin' },
        alwaysShow: false
      },
      {
        path: '/projectEnd',
        name: 'projectEnd',
        component: () => import('@/views/project/createProject/projectEnd/index'),
      } ,
      {
        path: '/distributionProject/dayTask',
        name: 'editProject',
        component: () => import('@/views/project/dayTask/index'),
        // meta: { title: '人天分配', icon: 'el-icon-tickets' }
      },
      {
        path: '/review',
        name: 'review',
        component: () => import('@/views/project/review/index'),
        // meta: { title: '评审设置', icon: 'el-icon-tickets' }
      },
      {
        path: '/distributionProject',
        name: 'distributionProject',
        component: () => import('@/views/project/distributionProject/index'),
        meta: { title: '项目详情', icon: 'el-icon-tickets' },
        alwaysShow: false
      },
      {
        path: '/change',
        name: '发起变更',
        component: () => import('@/views/warehouse/changes/index'),
        // meta: { title: '发起变更', icon: 'el-icon-tickets' }
      },
      {
        path: '/change/detail',
        name: '变更内容',
        component: () => import('@/views/warehouse/changes/detail'),
        // meta: { title: '变更内容', icon: 'el-icon-tickets' }
      },
      {
        path: '/test',
        name: '测试',
        component: () => import('@/views/test/index'),
        meta: { title: '测试', icon: 'el-icon-tickets' },
        alwaysShow: false
      }
    ]
  },

  {
    path: '/logAdmin',
    component: Layout,
    redirect: '/logAdmin',
    name: '工作日志',
    meta: { title: '工作日志', icon: 'el-icon-date' },
    children: [
      {
        path: '/myLog',
        name: '我的日志',
        component: () => import('@/views/myLog/index'),
        meta: { title: '我的日志', icon: 'el-icon-tickets' },
        buttonId: 'log.myLog.list'
      },
      {
        path: '/logReview',
        name: '日志评审',
        component: () => import('@/views/logReview/index'),
        meta: { title: '日志评审', icon: 'el-icon-edit-outline' },
        buttonId: 'log.logReview.list'
      },
      {
        path: '/logReview/:proNo/:workDate',
        name: '日志评审',
        component: () => import('@/views/logReview/index'),
        meta: { title: '日志评审', icon: 'el-icon-edit-outline' },
        buttonId: 'log.logReview.list',
        alwaysShow: false
      },
      {
        path: '/logReviewAgain',
        name: '人天统计',
        component: () => import('@/views/logReviewAgain/index'),
        meta: { title: '人天统计', icon: 'el-icon-document-checked' },
        buttonId: 'log.logReviewAgain.list'
      },
      {
        path: '/logEdit',
        name: '人天审查',
        component: () => import('@/views/logEdit/index'),
        meta: { title: '人天审查', icon: 'el-icon-edit' },
        buttonId: 'log.logEdit.list'
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
